$(document).ready(function() {
	mui.init();
	mui.plusReady(function() {
		var searchTime="";
		var dataTime="";
		var start_time="";
		var end_time="";
		var popupBtn=0;
		mui("body").on("tap", '.day, .month', function() {
			dataTime=$(this).attr("data-id");
			
			//判断点击事件，根据判断结果进行跳转
			//本地存储dataTime作为下一个页面的参数
//			localStorage.setItem("dataTime", $(this).attr("data-id"));
			if($(this).attr("data-id") == "0") {
				popupBtn=1;
//				mui.prompt('请输入要查询的日期', '例：2017-01-01', '天择可付', ["查询"], null, 'div');
                // 自定义日期弹框
				mui.confirm("<p id='startTime' class='timeId' data-id='start_time'>请选择开始日期</p><p id='endTime' class='timeId' data-id='end_time'>请选择结束日期</p>", "请选择需要查询的日期", ["查询", "取消"], function() {}, "div");
			} else {
				mui.openWindow({
					url:"../../../view/searchDetail.html", 
					id:"searchDetail",
					extras: {
						timess: dataTime
					}
				});
			}

		})

		mui("body").on("tap", ".timeId", function() { //点击了日期输入框
			self=$(this);
			var today=new Date();
			var nowTime=today.getFullYear()+"-"+(today.getMonth()<9?"0"+""+(today.getMonth()+1):(today.getMonth()+1))+"-"+today.getDate()+" "+(((today.getHours()<10))?("0"+today.getHours()):today.getHours())+":"+today.getMinutes();
			console.log(nowTime);
			var dtpicker = new mui.DtPicker({
				"type": "datetime",
				"value": nowTime
			})
			dtpicker.show(function(e) {
				self.html(e.value);
				if (self.attr("data-id")=="start_time") {
					start_time=$("#startTime").html();
				} else{
					end_time=$("#endTime").html();
				}
			})
		})
		
		mui("body").on("tap", ".search", function() {
			popupBtn=2;
			$("input").blur();
			var orderId=$(".order_id").val();
			if(!orderId){
				mui.alert("请输入订单号", " ", "关闭", function() {}, "div");
				return false;
			}
			require(weburl + model3, "json", "post", {
				token: localStorage.getItem("token"),
				out_trade_no: orderId,
				id: "null"
			}, function(response) {
				console.log(JSON.stringify(response))
				if(response.status == 1) {
					mui.openWindow({
						url: "../../detail.html",
						id: "detail.html",
						extras: {
							orderNum: response.data.out_trade_no
						}
					});
				} else {
					mui.alert("未查询到该订单", " ", "关闭", function() {}, "div");
				}
			}, function() {
				mui.alert("未查询到该订单", " ", "关闭", function() {}, "div");
			})
			return false;
		})
		
		mui("body").on("tap", ".mui-popup-button", function() {
			if ($(this).index()==0&&start_time!=""&&end_time!=""&&popupBtn==1) {
				mui.openWindow({
					url: "../../searchDetail.html",
					id: "searchResult",
					extras: {
						timess: dataTime,
						start_time:start_time+":00",
						end_time:end_time+":00"
					}
				})
			}else if($(this).index()==0&&start_time==""&&popupBtn==1){
				mui.toast('开始日期不能为空！',{ duration:'long', type:'div' });
			}
			else if($(this).index()==0&&end_time==""&&popupBtn==1){
				mui.toast('结束日期不能为空！',{ duration:'long', type:'div' });
			}
		})
		
	})
})